<?php
// +----------------------------------------------------------------------
// | YzdlmCompressImage [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2019 yzdlm All rights reserved.
// +----------------------------------------------------------------------
// | Author: yzdlm <1741509527@qq.com>
// +----------------------------------------------------------------------

namespace plugins\yzdlm_compress_image\controller;

use app\user\model\AssetModel;
use cmf\controller\PluginBaseController;
use plugins\yzdlm_compress_image\model\PluginYzdlmImageComressModel;

class IndexController extends PluginBaseController
{

    public function index()
    {

        $model = new PluginYzdlmImageComressModel($this->getPlugin()->getConfig());
        $id = $this->request->post('id');
        return json($model->index($id));
    }

    public function compress_image()
    {
        $list = AssetModel::where('more', '=', null)->order('create_time desc')
            ->paginate(1, false, ['page' => 1]);

        $success = 0;
        $fail = 0;
        foreach ($list as $key => $value) {

            if ($res['code'] == 0) {
                $success += 1;
            } else {
                $fail += 1;
            }
        }
        return '成功' . $success . '失败'.$fail;
    }


}